package com.dataaccess.dataaccess.support.utils;

import cn.hutool.core.date.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: YangYu
 * @ClassName: DateUtils
 * @Date: Created in 15:53 2023/7/10
 * @Description: 时间工具类
 */
public class DateUtils {

    /**
     * @Author YangYu
     * @Description 校验时间差
     * @Date Created in 15:54 2023/7/10
     * @Param [tableTime, hour]
     */

    public static boolean judgmentDate(String tableTime, double  hour) throws Exception {

        String currentTime = DateUtil.now();//当前时间

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d HH:mm:ss");

        Date start = sdf.parse(tableTime);//业务时间

        Date end = sdf.parse(currentTime);//当前时间

        long cha = end.getTime() - start.getTime();

        if (cha < 0) {

            return false;

        }
        double result = cha * 1.0 / (1000 * 60 * 60);

        if (result > hour) {

            return true;

        } else {

            return false;

        }

    }

    /**
     * 将毫秒转化为日期(格式:yyyy-MM-dd hh:mm:ss)
     *
     * @param l
     * @return
     * @throws Exception
     */
    public static String contextLoads(Long l) throws Exception {

        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        Date date = new Date(l);
        String str1 = sdf1.format(date);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date2 = sdf.parse(str1);
        String str2 = sdf.format(date2);
        return str2;
    }
}
